package cn.rdq.iknessplatform.service.impl;

import cn.rdq.api.dto.CatelogDramaItem;
import cn.rdq.api.po.CatelogDrama;
import cn.rdq.dao.CatelogDramaMapper;
import cn.rdq.iknessplatform.service.CatelogDramaService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CatelogDramaServiceImpl extends ServiceImpl<CatelogDramaMapper, CatelogDrama> implements CatelogDramaService {

    @Resource
    private CatelogDramaMapper catelogDramaMapper;

    @Override
    public List<CatelogDramaItem> catelogDramItems(CatelogDrama catelogDrama) {
        return null;
    }

    @Override
    public CatelogDramaItem getCatelogInfo(Long catelogId) {
        return catelogDramaMapper.getCatelogInfo(catelogId);
    }

    @Override
    public boolean addCatelogItem(CatelogDrama catelogDrama) {
        QueryWrapper<CatelogDrama> wrapper = new QueryWrapper<>();
        wrapper.eq("catelog_id", catelogDrama.getCatelogId())
                .eq("drama_id", catelogDrama.getDramaId());
        CatelogDrama one = getOne(wrapper);
        if (!ObjectUtils.isEmpty(one)) {
            return false;
        }
        return save(catelogDrama);
    }

    @Override
    public boolean deleteByCatelog(Long catelogId) {
        QueryWrapper<CatelogDrama> wrapper = new QueryWrapper<>();
        wrapper.eq("catelog_id", catelogId);
        return remove(wrapper);
    }
}
